package com.litchishell.easy;

/**
 * @author LitchiShell
 * @description: 题目：商品折扣后的最终价格
 * @create 2022-09-01
 */
public class Solution019 {
    public int[] finalPrices(int[] prices) {
        for (int i = 0; i < prices.length; i++) {
            int count = findCount(prices, prices[i], i + 1);
            if (count != -1) {
                prices[i] = prices[i] - prices[count];
            }
        }
        return prices;
    }

    public int findCount(int[] prices, int compare, int index) {
        int tag = -1;
        for (int i = index; i < prices.length; i++) {
            if (prices[i] <= compare)  {
                tag = i;
                break;
            }
        }
        return tag;
    }
}
